// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const rightCollection = db.collection('right')

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const id = event.id
  const state = event.state //'agree' 'refuse'
  let message = 0
  if(state == 'agree'){
    await rightCollection.doc(id).update({
      data: {
        status: 2,
        applyDate: new Date().getTime()
      }
    }).then(res => {
      message = 2
    })
  }else{
    await rightCollection.doc(id).update({
      data: {
        status: 3
      }
    }).then(res => {
      message = 3
    })
  }
  return message //2同意 3拒绝
}